/* This file is part of SpaceSim.
 
 SpaceSim is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 SpaceSim is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with SpaceSim.  If not, see <http://www.gnu.org/licenses/>. */

#include "random.h"

std::tr1::mt19937 Random::int_engine;
std::tr1::ranlux64_base_01 Random::float_engine;

void Random::Seed(int seed) {
	int_engine.seed(seed);
	float_engine.seed(seed);
}

int Random::Rand(int min, int max) {		// generate random numbers with a uniform distribution
	std::tr1::uniform_int<int> dist(min, max);
	return dist(int_engine);
}

float Random::Rand(float min, float max) {		// generate random numbers with a uniform distribution
	std::tr1::uniform_int<float> dist(min, max);
	return dist(float_engine);
}

int Random::NormalRand(int min, int max) {	// generate random numbers with a normal/Gaussian distribution
	// mu is the mean, basically the middle between min and max
	int mu = (max - min) / 2;
	// anything further than 3 sigma from mu is neglegible, so that will be our limit
	int sigma = (max - min) / 6;
	std::tr1::normal_distribution<int> dist(mu, sigma);
	return dist(int_engine);
}

float Random::NormalRand(float min, float max) {	// generate random numbers with a normal/Gaussian distribution
	// mu is the mean, basically the middle between min and max
	float mu = (max - min) / 2;
	// anything further than 3 sigma from mu is neglegible, so that will be our limit
	float sigma = (max - min) / 6;
	std::tr1::normal_distribution<float> dist(mu, sigma);
	return dist(float_engine);
}

double Random::NormalRand(double min, double max) {	// generate random numbers with a normal/Gaussian distribution
	// mu is the mean, basically the middle between min and max
	double mu = (max - min) / 2.0;
	// anything further than 3 sigma from mu is neglegible, so that will be our limit
	double sigma = (max - min) / 6.0;
	std::tr1::normal_distribution<double> dist(mu, sigma);
	dist.reset();
	return dist(float_engine);
}

float Random::GammaRand(float k) {
	std::tr1::gamma_distribution<float> dist(k);
	return dist(float_engine);
}

float Random::ExponentialRand(float lambda) {
	std::tr1::exponential_distribution<float> dist(lambda);
	return dist(float_engine);
}